package pri.jz.keeper.ui.view

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import pri.jz.keeper.R
import pri.jz.keeper.ui.theme.Grey3
import pri.jz.keeper.ui.theme.MainThemeColor

/**
 *Author by: JZ
 *Email: 2451756617@qq.com
 *PS:
 */
/**
 * 主题按钮，也为最常的按钮
 * @param modifier
 * @param text 按钮文字
 * @param textSize 按钮文字大小
 * @param onClick
 */
@Composable
fun MainButton(
    modifier: Modifier = Modifier,
    text: String = "确认",
    textSize: TextUnit = 16.sp,
    enabled: Boolean = true, //是否可点击
    onClick: () -> Unit
) {
    Box(
        modifier = modifier
            .clip(RoundedCornerShape(15.dp))
            .background(if (enabled) MainThemeColor else Brush.horizontalGradient(listOf(Grey3,
                Grey3)))
            .clickable(enabled = enabled) { onClick() },
        contentAlignment = Alignment.Center
    ) {
        ProvideTextStyle(
            value = MaterialTheme.typography.button
        ) {
            Text(
                text, fontSize = textSize, color = Color.White,
                modifier = Modifier.padding(horizontal = 20.dp, vertical = 10.dp)
            )
        }
    }
}
